//
//  AboutTableViewController.m
//  AirConditioner
//
//  Created by Sean Wang on 12-4-26.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "AboutTableViewController.h"
#import "AboutDetailViewController.h"
#import "CustomerCareViewController.h"
#import "LegalViewController.h"
#import "CreditsViewController.h"

@interface AboutTableViewController ()

@end

@implementation AboutTableViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        UIBarButtonItem *temporaryBarButtonItem = [[UIBarButtonItem alloc] init];
        temporaryBarButtonItem.title = @"Back";
        self.navigationItem.backBarButtonItem = temporaryBarButtonItem;
    }
    return self;
}

- (id)initWithStyle:(UITableViewStyle)style
{
    self = [super initWithStyle:style];
    if (self) {
        //self.view.backgroundColor = [UIColor clearColor];        
        self.title = NSLocalizedString(@"About", @"About");
        self.tabBarItem.image = [UIImage imageNamed:@"84-lightbulb"];
        self.tableView.separatorColor = [UIColor clearColor];
        self.tableView.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bg-black.png"]];
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];

    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;
 
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

#pragma mark - Table view data source

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 4;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"aboutCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if(cell == nil){
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
        //cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
        cell.textLabel.textColor = [UIColor whiteColor];
        cell.textLabel.font = [UIFont boldSystemFontOfSize:15];
        cell.textLabel.backgroundColor= [UIColor clearColor];   
        
        UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bg-row-basics.png"]];
        UIImageView *highlightImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bg-row-basicsb.png"]];
        cell.backgroundView = imageView;
        cell.selectedBackgroundView = highlightImageView;
    }
    
    switch (indexPath.row) {
        case 0:
            cell.textLabel.text = @"About";
            break;
        case 1:
            cell.textLabel.text = @"NCG Customer Care";
            break;
        case 2:
            cell.textLabel.text = @"Legal";
            break;
        case 3:
            cell.textLabel.text = @"Credits";
            break;
        default:
            return nil;
    }
    
    return cell;
}

#pragma mark - Table view delegate

- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath
{
    [self rowSelected:indexPath.row];
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    [self rowSelected:indexPath.row];
}

- (void) rowSelected:(NSInteger)row
{
    switch (row) {
        case 0:
            if (aboutDetailViewController == nil) {
                aboutDetailViewController = [[AboutDetailViewController alloc] initWithNibName:@"AboutDetailViewController" bundle:nil];                
            }
            [self.navigationController pushViewController:aboutDetailViewController animated:YES];
            break;
        case 1:
            if (customerCareViewController == nil) {
                customerCareViewController = [[CustomerCareViewController alloc] initWithNibName:@"CustomerCareViewController" bundle:nil];                
            }
            [self.navigationController pushViewController:customerCareViewController animated:YES];
            break;
        case 2:
            if (legalViewController == nil) {
                legalViewController = [[LegalViewController alloc] initWithNibName:@"LegalViewController" bundle:nil];                
            }
            [self.navigationController pushViewController:legalViewController animated:YES];
            break;
        case 3:
            if (creditsViewController == nil) {
                creditsViewController = [[CreditsViewController alloc] initWithNibName:@"CreditsViewController" bundle:nil];                
            }
            [self.navigationController pushViewController:creditsViewController animated:YES];
            break;
        default:
            break;
    }
}
@end
